// go语言结构体
package main

import "fmt"

/**
 * 结构体声明格式
 * type struct_variable_type struct {
 *  member definition
 *  member definition
 *  ...
 *  member definition
 * }
 */
type Books struct {
	title   string
	author  string
	subject string
	book_id int
}

func t1() {
	// 创建以恶搞新单结构体
	fmt.Println(Books{"Go 语言", "www.lbs.com", "Go 语言编程", 123456})
	fmt.Println(Books{title: "Go", author: "lbs", subject: "Go", book_id: 123})
	// 忽略的字段为 0 或 空
	fmt.Println(Books{title: "Go", author: "Go"})
}

/**
 * 访问结构体成员格式
 * struct_name.struct_member
 */
func t2() {
	book := Books{"Go 语言", "www.lbs.com", "Go 语言编程", 123456}
	fmt.Println(book.title)
	fmt.Println(book.author)
	fmt.Println(book.subject)
	fmt.Println(book.book_id)
}

/**
 * 结构体作为函数参数
 */
func t3(book *Books) {
	fmt.Println(book.title)
	fmt.Println(book.author)
	fmt.Println(book.subject)
	fmt.Println(book.book_id)
}

/**
 * 结构体指针
 * var struct_pointer *Books
 */
func t4() {
	book1 := Books{"Go 语言", "www.lbs.com", "Go 语言编程", 123456}
	book2 := Books{"Go 语言", "www.lbs.com", "Go 语言编程", 123456}
	t3(&book1)
	t3(&book2)
}
